﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.CodeDom;

namespace ExampleCallNoWin
{
    public class Shell
    {
        /// <summary>
        /// 开启控制台命令行窗口
        /// </summary>
        /// <returns></returns>
        [DllImport("kernel32.dll")]
        public static extern Boolean AllocConsole();
        [DllImport("kernel32.dll")]
        public static extern Boolean FreeConsole();

        [DllImport("user32.dll")]
        public static extern Boolean PostThreadMessageA(int threadId, uint msg, IntPtr wParam, IntPtr lParam);

        /// <summary>  
        /// 输出信息  
        /// </summary>  
        /// <param name="format"></param>  
        /// <param name="args"></param>  
        public static void WriteLine(string format, params object[] args)
        {
            WriteLine(string.Format(format, args));
        }

        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool PostMessage(int id,uint msg)
        {
            return PostThreadMessageA(id, msg, IntPtr.Zero, IntPtr.Zero);
        }

    }
}
